package com.ruoyi.project.system.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.project.system.domain.SysDate;
import com.ruoyi.project.system.mapper.SysDateMapper;
import com.ruoyi.project.system.service.ISysDateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class SysDateServiceImp implements ISysDateService {
    @Autowired
    private SysDateMapper dateMapper;

    @Override
    public List<SysDate> selectDateList(String yearOrMonth) {
        return dateMapper.selectDateList(yearOrMonth);
    }

    @Override
    public int insertDate(SysDate date) {
        if(dateMapper.checkDateExist(date.getDate()) > 0){
            return 0;
        }
        return dateMapper.insertDate(date);
    }

    @Override
    public int updateDate(SysDate date) {
        return dateMapper.updateDate(date);
    }

    @Override
    public int deleteDate(Long id) {
        return dateMapper.deleteDate(id);
    }

    public static void main() throws Exception
    {
        Date startDate = DateUtils.dateTime("yyyy-MM-dd", "2025-01-01");
        do{
            SysDate sysDate = new SysDate();
            sysDate.setDate(startDate);
            System.out.println("================== 日期：" + DateUtils.parseDateToStr("yyyy-MM-dd", startDate));
            startDate = DateUtils.addDays(startDate, 1);
        }while (startDate.getYear() == 2025);
    }
}
